import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Boulder here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Boulder extends Trap
{
    private int yVel=0;
    private int dir;
    private int xVel=20;
    private Timer spawnTimer=new Timer();
    private CollisionBox colDown;
    private boolean addedToWorld=false;
    
    private static final int RIGHT=0;
    private static final int LEFT=1;
    
    public Boulder(int x,int del,int iniD,int d,int xV,int skin)
    {
        super(x,del,iniD);
        
        dir=d;
        xVel=xV;
        
        damage=10;
        if(skin==9001)
        damage=110;
        
        GreenfootImage image;
        
        switch(skin)
        {
            case 1:     image=new GreenfootImage("rock_jungle1.png");
                        break;
            case 2:     image=new GreenfootImage("rock_jungle2.png");
                        break;
            case 9001:  image=new GreenfootImage("boulder.png");
                        break;
            default:    image=new GreenfootImage("rock.png");
                        break;
        }
        
        image.setTransparency(0);
        setImage(image);
        
        colDown=new CollisionBox(this,0,getImage().getHeight()/2+10,10,10);
    }
        
    
    public void act() 
    {
        timer.tick();
        activeTimer.tick();
        
        GameWorld world=(GameWorld)getWorld();
        
        if(dir==2)
        {
            if(getX()>getPlayer().getX())
            dir=1;
            else
            dir=0;
        }
        
        if(addedToWorld==false)
        {
            addedToWorld=true;
            world.addObject(colDown,getX(),getY());
        }
        
        
        if(active==true || !activeTimer.wait(initialDelay))     
        activeImage();
        if(active==false)
        return;
        
        if(colDown.isTouchingGround())
        {
            yVel=-1;
            setLocation(getX(),world.getHeight()-95-getImage().getHeight()/2);
        }   
        
        yVel+=1;
        setLocation(world.getScrollx()+360+posX,getY()+yVel);
        
        if(isTouchingPlayer())
            getPlayer().getHurt(damage);
        
        if(timer.wait(100))
        return;
        
        
        if(dir==RIGHT)
        {
            posX+=xVel;
            turn(45);
        }
        else
        {
            posX-=xVel;
            turn(-45);
        }
        
        if(getY()>world.getHeight()+getImage().getHeight())
        world.removeObject(this);
    }
}
